import {compose, lifecycle, withHandlers, withState} from "recompose"
import {del, get, postJSON, postParam, putJSON, putParam} from "server"
import React from "react"

const orderCompose = compose(
  withState('data', '$data', undefined),
  withHandlers({
    getOrderInfo: ({match, $data}) => {
      return () => {
        const id = match.params.id
        get(`/order/${id}`, {})
          .then(data => $data(data))
      }
    },
    onNeedPrintChange: ({data}) => {
      return (checked) => {
        get(`/order/fee/${data.id}`, {needPrint: checked})
          .then(fee => data.feeDetail = fee)
      }
    }
  }),
  lifecycle({
    componentDidMount() {
      const {getOrderInfo} = this.props
      getOrderInfo()
    }
  })
)

export default orderCompose